package com.example.excel.Listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Timestamp;


public class ContextListener implements ServletContextListener, ServletContextAttributeListener {


    @Override
    public void contextDestroyed(ServletContextEvent event) {
        System.out.println(new Timestamp(System.currentTimeMillis()) + "项目销毁");
    }

    //上下文域初始化
    @Override
    public void contextInitialized(ServletContextEvent event) {
        System.out.println(new Timestamp(System.currentTimeMillis()) + "项目加载");
    }

    //属性增加
    @Override
    public void attributeAdded(ServletContextAttributeEvent event) {

        System.out.println("添加的属性名：" + event.getName());
        System.out.println("添加的值：" + event.getValue());
    }

    //属性的删除
    @Override
    public void attributeRemoved(ServletContextAttributeEvent event) {
        System.out.println("删除属性名：" + event.getName());
        System.out.println("删除值：" + event.getValue());
    }

    //属性的修改
    @Override
    public void attributeReplaced(ServletContextAttributeEvent event) {
        System.out.println("修改属性名：" + event.getName());
//修改前的值
        System.out.println("修改前的值：" + event.getValue());
//修改后的值
        System.out.println("修改后的值：" +
                event.getServletContext().getAttribute(event.getName()));
    }


}
